package hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

/**
 * @author Lu Ruotong
 * @date 2022/3/12 19:26
 */

public class HadoopCase {
    public static void main(String[] args) {
        try {

            System.setProperty("hadoop.home.dir", "D:\\18code\\hadoop-2.7.3");

            System.setProperty("HADOOP_USER_NAME", "root");

            String fileName = "/student_data";

            Configuration conf = new Configuration();

            conf.set("fs.defaultFS", "hdfs://192.168.116.11:9000");

            conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");

            FileSystem fs = FileSystem.get(conf);

            if (fs.exists(new Path(fileName))) {
//                fs判断 /student_data文件是否存在
                System.out.println("文件存在");
            } else {
                System.out.println("文件不存在");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
